﻿function windowsShow(content,i,s) {
	art.dialog({
			beforeunload:function () {
				$(i).focus();
			},
			fixed: true,
			lock: true,
			title:"提示",
			content: content,
			width: 300,
			height: 30,
			okValue:'确定',
			ok: function() { }
		});
}
function Checking(p,s) {
	var id = $(p).attr("id");
	$(p).focus().after(function() {
		if ($("#" + id + "+span").html() == null) return "<span class=\"formErrorContent\">" + s + "</span>";
	}).focusout(function() {
		if ($(p).val().length > 0 && $.trim($(p).val()).length > 0) {$("#" + id + "+span").remove();$(p).unbind("focusout");}
	});
}
$(function() {
	var phoneEx = /((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/;
	var mail = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
	var code = /(\d{6})/;
	var username, sex, age, profession, address, zipcode, email, phone;
	$("#Next").live("click", function() {
		username = $("#Name").val(), sex = $("input[name='cSex']:checked+label").html(), age = $("input[name='cAge']:checked+label").html();
		if (username.length == 0 || $.trim(username).length == 0)
		{windowsShow("请填写您的姓名！",$("#Name"),"姓名不能为空！");return false;}
		if (sex==undefined)
		{windowsShow("请选择您的性别！",$("input[name='cSex']:checked+label"),"");return false;}
		if (age==undefined)
		{windowsShow("请选择您的年龄！",$("input[name='cAge']:checked+label"),"");return false;}
		if ($("#profession").val().length == 0 || $.trim($("#profession").val()).length == 0)
		{windowsShow("请填写您的职业！",$("#profession"),"职业内容不能为空！");return false;} else {profession = $("#profession").val();}
		if ($("#address").val().length == 0 || $.trim($("#address").val()).length == 0)
		{windowsShow("请填写您的联系地址！",$("#address"),"联系地址不能为空！");;return false;} else {address = $("#address").val();}
		if ($("#zipcode").val().length == 0 || $.trim($("#zipcode").val()).length == 0)
		{windowsShow("请填写您所在地区的邮政编码！",$("#zipcode"),"邮政编码不能为空！");return false;} else {
			zipcode = $("#zipcode").val();
			if (!code.exec(zipcode)) {windowsShow("请输入正确的邮政编码格式！",$("#zipcode"),"请输入6位数字的邮政编码！");;return false;}
		}
		if ($("#email").val().length == 0 || $.trim($("#email").val()).length == 0)
		{windowsShow("请填写您的邮箱地址！",$("#email"),"邮箱地址不能为空！");return false;} else {
			email = $("#email").val();
			if (!mail.exec(email)) {windowsShow("请填写正确的邮箱地址！",$("#email"),"例：abc@qq.com ！");return false;}
		}
		if ($("#phone").val().length == 0 || $.trim($("#phone").val()).length == 0)
		{windowsShow("请填写您的联系方式！",$("#phone"),"联系方式不能为空！");return false;} else {
			phone = $("#phone").val();
			if (!phoneEx.exec(phone)) {windowsShow("请填写正确的联系方式！",$("#phone"),"请输入11位有效手机号码！");return false;}
		}
		$.post("./Handler/Event.ashx", { "flag": "reguser", "name": username, "sex": sex, "age": age, "profession": profession, "address": address, "zipcode": zipcode, "email": email, "phone": phone }, function(msg) {
			if (msg == "true")
				document.location.href = "./question.html";
		}, "html");
		
	});
});
